<template>
  <div>
    <ul>
      <li v-for="product in all">
        {{ product.title }} : ￥{{ product.price }} 
        <button :disabled="product.inventory <= 0" @click="addToCart(product)">放入购物车</button>
      </li>
    </ul>
  </div>
</template>

<script>
  import { mapState, mapActions } from 'vuex'
  export default {
    computed: {
      ...mapState('products', ['all'])
    },

    methods: {
      ...mapActions('products', ['loadProducts']),
      ...mapActions('cart', ['addToCart'])
    },

    mounted() {
      this.loadProducts()
    }
  }
</script>

<style scoped>

</style>